(function ($) {
    $.fn.objDigo = function (InIt) {

        var controlMapExisting=new Array(0);
        var controlMapCurrent=new Array(0);

        var xmlName = '';

        var mapData;

        this.onLoad = function () {

            this.loadHTML();

            document.getElementById("title").innerHTML = jQuery.i18n.prop(InIt);

            var xml = getData(xmlName);

            var arrayLabels = document.getElementsByTagName("label");
            lableLocaliztion(arrayLabels);

            var buttonID = document.getElementById("btRun").id;
            buttonLocaliztion(buttonID);
	    	    
            document.getElementById('txtarOutput').readOnly = true;

            document.getElementById('tooldropdown').options[0].selected = true;

            document.getElementById('lDiaErrorMsg').style.display = 'none';
            $('#tooldropdown').focus();
            $('#tooldropdown').focus();

        }

        this.onPost = function () {
            if (this.isToolSelected()) {
		
                document.getElementById('lDiaErrorMsg').style.display = 'none';

                if (this.isValid()) {

                    //document.getElementById('lDiaErrorMsg').style.display = 'none';
                    mapData=null;
                    mapData = new Array();
		
                    var index = 0 ;
                    var cmd = document.getElementById('tooldropdown').value;
                    var arg = document.getElementById('tbParams').value;
                    this.putMapElement(index++,"RGW/diagnostic/command",cmd);
                    this.putMapElement(index,"RGW/diagnostic/arg",arg);

                    postXML(xmlName, g_objXML.getXMLDocToString(g_objXML.createXML(mapData)),30000);
                    return true;
                //alert(g_objXML.getXMLDocToString(g_objXML.createXML(mapData)));
                //this.onLoad();
		  

                }
                else {
                    document.getElementById('lDiaErrorMsg').style.display = 'block';
                    document.getElementById('lDiaErrorMsg').innerHTML =  jQuery.i18n.prop('lInvalidCharErrorMsg');
                    return false;
                }
            }
        }
        this.onPostSuccess = function(){
            var xml = getData(xmlName);
            output=$(xml).find("output").text();

            document.getElementById('txtarOutput').readOnly = false;
            document.getElementById('txtarOutput').value = output;
            document.getElementById('txtarOutput').readOnly = true;

        }
        this.isToolSelected = function () {
            var selToolData = document.getElementById("tooldropdown").value;
            if (selToolData=='select') {
                document.getElementById('lDiaErrorMsg').style.display = 'block';
                document.getElementById('lDiaErrorMsg').innerHTML =  jQuery.i18n.prop('lSelectToolErrorMsg');
                return false;
            }
            return true;
        }

        this.isValid = function () {
            var str = document.getElementById("tbParams").value;
            if ( (str.indexOf(";")) != -1) {
                return false;
            }
            else if ( (str.indexOf("~")) != -1) {
                return false;
            }
            else if ( (str.indexOf("|")) != -1) {
                return false;
            }
            else if ( (str.indexOf("<")) != -1) {
                return false;
            }
            else if ( (str.indexOf(">")) != -1) {
                return false;
            }
            else if ( (str.indexOf("#")) != -1) {
                return false;
            }
            else if ( (str.indexOf("&")) != -1) {
                return false;
            }
            else if ( (str.indexOf("$")) != -1) {
                return false;
            }
            return true;
        }

        this.putMapElement = function(index,xpath,value){
            mapData[index]=new Array(2);
            mapData[index][0]=xpath;
            mapData[index][1]=value;
        }

        this.loadHTML =  function() {
            document.getElementById('Content').innerHTML ="";
            document.getElementById('Content').innerHTML = callProductHTML("html/router/diagnostics.html");
        }

        this.setXMLName = function (_xmlname){
            xmlName = _xmlname;
        }

        return this.each(function () {

            });

    }
})(jQuery);

function tooldropdownChanged()
{
    document.getElementById("tbParams").value="";
    document.getElementById("txtarOutput").value="";
}
function checkEnterDignostics(e)
{

    var characterCode;
    if(e && e.which){
        e = e
        characterCode = e.which
    } else {
        e = event
        characterCode = e.keyCode
    }
    if(characterCode == 13){
        setData();
    }
}